//
//  PushTransitionAnimation.m
//  UI29-transitionAnimation转场动画
//
//  Created by 韩旭 on 16/8/23.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "PushTransitionAnimation.h"
#import "ViewController.h"
#import "SecondViewController.h"
@implementation PushTransitionAnimation

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5f;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    ViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    SecondViewController *secondVC = [transitionContext viewControllerForKey: UITransitionContextToViewControllerKey];
    UIView *containView = [transitionContext containerView];
    [containView addSubview:secondVC.view];
    secondVC.ImageSecond.hidden = YES;
    //    截图大发
    UIView *snapView = [fromVC.fromImage snapshotViewAfterScreenUpdates:NO];
    snapView.frame = fromVC.fromImage.frame;
    [containView addSubview:snapView];
   [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
    [containView layoutIfNeeded];
    snapView.frame = secondVC.ImageSecond.frame;
} completion:^(BOOL finished) {
    secondVC.ImageSecond.hidden = NO;
    [snapView removeFromSuperview];
    [transitionContext completeTransition:YES];
}];
    
}




@end
